from django.db import models


# Create your models here.
# 商家表
class ShopsModel(models.Model):
    nickname = models.CharField(verbose_name="名称", max_length=20)
    avatar_url = models.CharField(verbose_name="用户头像", max_length=256, null=True)
    intro = models.CharField(verbose_name="个性签名", max_length=30, default="商家很懒")
    address = models.CharField(verbose_name="地址", max_length=128)
    mobile = models.CharField(verbose_name="手机号", max_length=11)
    password = models.CharField(verbose_name="密码", max_length=256)
    work_time = models.CharField(verbose_name="营业时间", max_length=11, default="8:00-20:00")
    start_price = models.DecimalField(verbose_name="起送费", max_digits=5, decimal_places=2, default=5)
    is_apply = models.BooleanField(verbose_name="申请是否通过", default=False)
    date_joined = models.DateTimeField(verbose_name="注册时间", auto_now_add=True)
    last_login = models.DateTimeField(verbose_name="上次登录时间", null=True)
    is_delete = models.BooleanField(verbose_name="是否删除", default=False)

    class Meta:
        db_table="shops_tb"
        verbose_name_plural = "商家表"

    def __str__(self):
        return self.nickname


# 商品类型表
class GoodTypeModel(models.Model):
    name = models.CharField(verbose_name="分类名称", max_length=20)
    shops = models.ForeignKey(verbose_name="商家", to=ShopsModel, on_delete=models.CASCADE)
    is_delete = models.BooleanField(verbose_name="是否删除", default=False)

    class Meta:
        db_table = "goods_type_tb"
        verbose_name_plural = "商品类别表"

    def __str__(self):
        return self.name


# 商品表
class GoodsModel(models.Model):
    type = models.ForeignKey(verbose_name="类别", to=GoodTypeModel, on_delete=models.CASCADE)
    name = models.CharField(verbose_name="商品名称", max_length=20)
    price = models.DecimalField(verbose_name="价格", max_digits=7, decimal_places=2)
    image = models.CharField(verbose_name="图片", max_length=256)
    create_time = models.DateTimeField(verbose_name="创建时间", auto_now_add=True)
    is_delete = models.BooleanField(verbose_name="是否删除", default=False)

    class Meta:
        db_table="goods_tb"
        verbose_name_plural = "商品表"

    def __str__(self):
        return "%s 类别 %s 商家 %s"%(self.name,self.type.name,self.type.shops.nickname)




